<?php  

require('init.php');
require('./classes/steamapi/functions.php');
include('inc/top.php');

if ($user->data['group_id'] != $mgmtgroup) { echo '<div id="main_yellow"><p>You must be an administrator to view this page.</p></div>'; } else {

if (!$phpbb_groups_enabled) { echo '<div id="main_yellow"><p>phpBB groups integration is not enabled.</p></div>'; } else {

$searchbox = sanitizeString($_POST['searchbox']);

$pagenum = $_GET['pagenum'];
if (!(isset($pagenum))) 
{ 
$pagenum = 1; 
} 

if (isset($_POST['searchbox'])) {
	$data_tmp = mysql_query("SELECT * FROM sm_groups_phpbb WHERE name LIKE '%{$searchbox}%'");
} else {
	$data_tmp = mysql_query("SELECT * FROM sm_groups_phpbb")/*  or die(mysql_error()) */;
}

if (empty($data_tmp)) { echo "<p>No Groups Found.</p>"; } else {

$rows = mysql_num_rows($data_tmp);
$pagenum = sanitizeString($pagenum); 
$page_rows = $maxresults;
$last = ceil($rows/$page_rows); 
if ($pagenum < 1) 
{ 
$pagenum = 1; 
} 
elseif ($pagenum > $last) 
{ 
$pagenum = $last; 
} 
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; 

if (isset($_POST['searchbox'])) {
	$data_p = mysql_query("SELECT * FROM sm_groups_phpbb WHERE name LIKE '%{$searchbox}%' ORDER BY id ASC {$max}"); 
} else {
	$data_p = mysql_query("SELECT * FROM sm_groups_phpbb ORDER BY id ASC $max")/*  or die(mysql_error()) */; 
}
}
?>

<div id="main_gray"><h1>phpBB Group List</h1></div>


<br />
<?php  

	if ($data_p == NULL) { echo "<div id='main_red'><p>No Groups Found.</p></div>"; } else {
	
?>
<div class="border2">
<table class="table" cellpadding="0" cellspacing="0" align="center" width="760">

<tr height="37" class="tr_th">
	<th>ID</th><th>Name</th><th>Flags</th><th>Immunity</th>
</tr>

<?php 

while($info = mysql_fetch_array($data_p)) 
{ 

	//OK, now we have the group info, get the name from the database as well.
	$bbgroup_query = mysql_query("SELECT group_name FROM $phpbbdb." . GROUPS_TABLE . " WHERE group_id = '" . $info['id'] . "';") or die(mysql_error());
	$bbgroup_result = mysql_fetch_assoc($bbgroup_query);

?>
		<tr onClick="parent.location='editgroup_phpbb.php?id=<?php  echo $info['id']; ?>'" onmouseover="cursor='pointer'" height="37" id="trhov">

			<td><?php  echo $info['id']; ?></td>
			<td><?php  echo $bbgroup_result['group_name']; ?></td>
			<td><?php  echo $info['flags']; ?></td>
			<td><?php  echo $info['immunity_level']; ?></td>
		</tr>

<?php 
}

?>
</table>
</div>

<?php 

echo "<p class='pages'>";
if ($pagenum == 1) 
{
} 
else 
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'><img src='images/icons/first.png' border='0'></a>";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'><img src='images/icons/back.png' border='0'></a>";
} 
echo " Page $pagenum of $last ";
if ($pagenum == $last) 
{
} 
else {
$next = $pagenum+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'><img src='images/icons/next.png' border='0'></a>";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'><img src='images/icons/last.png' border='0'></a>";
}
echo "</p>";
}
}
}
include('inc/bottom.php');
?>